<?php
$q=$_GET["q"];
$array= explode(",",$q);
$gra=$array[0];
$School_Id=$array[1];
$hint="";
$nothing="";
$first_option="";
$first_year="";
include_once '../Login/databaseconnection.php';
if($gra!="Select One"&&$School_Id!="")
{
$hint=$hint.'<form name="Stu_Year">
		 <label>Year:</label>';
       $hint=$hint."<select name='Student_Year' id='$School_Id' onChange='stu_getyear(this.value,this.id)' onmouseover='clearpopbox()'>";
	  $proyear=mysql_query("SELECT DISTINCT(Year) FROM programmes WHERE School_Id='$School_Id' AND Grade='$gra'");
	  if($proyear)
	  {
 while($rowyear=mysql_fetch_array($proyear))
  {
	 $Year=$rowyear['Year'];
	 $hint=$hint.'<option value="'.$Year.'">'.$Year.'</option>';
	 $nothing="false";	
if(empty($first_option))
{
$first_option=$Year;
}
  }
  }
   if($nothing!="false")
{
$hint=$hint.'<option value="">No result</option>';
}
$hint=$hint.'</select>
         </form><div id="stu_year">';
$stud=mysql_query("SELECT * FROM students WHERE Grade='$gra' AND School_Id='$School_Id' AND Year='$first_option'");
if($stud)
{
if($row_stud=mysql_fetch_array($stud))
{
$Gra_Male_Students=$row_stud['No_of_Male'];
$Gra_Female_Students=$row_stud['No_of_Female'];
}
else
{
$Gra_Male_Students='0';
$Gra_Female_Students='0';
}
}
$hint=$hint.'<table height="80" class="imgholder">
           <tr>
        <th>        
        </th>
         <td>
        </td>
         </tr> 
      <tr>
        <th>        
         <label>Total number of male students:</label>
         </th>
         <td>';
         $hint=$hint."<input type='text' name='Gra_Male_Students' value='$Gra_Male_Students' readonly='readonly' onmouseover='clearpopbox()'/>";
$hint=$hint.'</td>
         </tr>
         <tr>
        <th>        
         <label>Total number of female students:</label>
         </th>
         <td>';
         $hint=$hint."<input type='text' name='Gra_Female_Students' value='$Gra_Female_Students' readonly='readonly' onmouseover='clearpopbox()'/>";
$hint=$hint.'</td>
         </tr>
         <tr>
        <th>        
        </th>
         <td>
        </td>
         </tr> 
         <tr>
        <td>
         </td>
         <td>
		 </td>
         </tr>
		 </table>
		 <label>Programme Name:</label>';
		 $hint=$hint."<select name='Student_Programme_Name' id='$School_Id' onChange='get_stu_details(this.value,this.id)' onmouseover='clearpopbox()'>";
	 
	  $pro=mysql_query("SELECT DISTINCT(Programme_Id) FROM programmes WHERE School_Id='$School_Id' AND Grade='$gra' AND Year='$first_option'");
	  if($pro)
	  {
 while($row=mysql_fetch_array($pro))
  {
	 $Pro_Id=$row['Programme_Id'];
	  $resultp=mysql_query("SELECT * FROM programme WHERE Programme_Id='$Pro_Id'");
  if($rowp=mysql_fetch_array($resultp))
  {
		$pro_name=$rowp['Programme_Name'];
}
$nothing="false";
 if(empty($first_prog))
{
$first_prog=$Pro_Id;
}
$hint=$hint.'<option value="'.$pro_name.'">'.$pro_name.'</option>';
  }
  
  }
   if($nothing!="false")
{
$hint=$hint.'<option value="">No result</option>';
}
$hint=$hint.'</select>';
$prog=mysql_query("SELECT * FROM programmes WHERE Year='$first_option' AND Programme_Id='$first_prog' AND School_Id='$School_Id' AND Grade='$gra'");
if($prog)
{
if($row_prog=mysql_fetch_array($prog))
{
$Gra_Male_Students=$row_prog['No_Of_Male_Students'];
$Gra_Female_Students=$row_prog['No_Of_Female_Students'];
}
else
{
$Gra_Male_Students='0';
$Gra_Female_Students='0';
}
}
$hint=$hint.'<div id="stu_year_details"><table height="100" class="imgholder">
          <tr>
        <td> </td>
         <td></td>
         </tr>
         <tr>
        <th>        
        </th>
         <td>
        </td>
         </tr> 
          <tr>
        <th>        
         <label>Number of male students:</label>
         </th>
         <td>';
        $hint=$hint."<input type='text' name='Gra_Male_Students' value='$Gra_Male_Students' readonly='readonly' onmouseover='clearpopbox()'/>";
$hint=$hint.'</td>
         </tr>
         <tr>
        <th>        
         <label>Number of female students:</label>
         </th>
         <td>';
        $hint=$hint."<input type='text' name='Gra_Female_Students' value='$Gra_Female_Students' readonly='readonly' onmouseover='clearpopbox()'/>";
$hint=$hint.'</td>
         </tr>
         </table></div></div>';
}
if($hint=="")
{
if($School_Id=="")
{
$response="<font color='red'>*Please select a school!</font>";
}
$response=$response.'<form name="Stu_Year">
		 <label>Year:</label>';
       $response=$response."<select name='Student_Year' id='' onChange='stu_getyear(this.value,this.id)'>";
	 $response=$response.'<option value="Select One">Select One</option>';
	  $proyear=mysql_query("SELECT DISTINCT(Year) FROM programmes");
 while($rowyear=mysql_fetch_array($proyear))
  {
	 $Year=$rowyear['Year'];
	 $response=$response.'<option value="'.$Year.'">'.$Year.'</option>';
  }
$response=$response.'</select>
          </form>
<div id="stu_year">';
$response=$response.'<table height="80" class="imgholder">
           <tr>
        <th>        
        </th>
         <td>
        </td>
         </tr> 
      <tr>
        <th>        
         <label>Total number of male students:</label>
         </th>
         <td>';
         $response=$response."<input type='text' name='Gra_Male_Students' readonly='readonly'/>";
$response=$response.'</td>
         </tr>
         <tr>
        <th>        
         <label>Total number of female students:</label>
         </th>
         <td>';
         $response=$response."<input type='text' name='Gra_Female_Students' readonly='readonly'/>";
$response=$response.'</td>
         </tr>
         <tr>
        <th>        
        </th>
         <td>
        </td>
         </tr> 
         <tr>
        <td>        
        </td>
         <td></td>
         </tr></table>
<label>Programme:</label><select name="Student_Programme_Name" id="" onChange="get_stu_details(this.value,this.id)">';
	  $response=$response.'<option value="Select One">Select One</option>';
	  $pro=mysql_query("SELECT DISTINCT(Programme_Id) FROM programmes");
 while($row=mysql_fetch_array($pro))
  {
	 $Pro_Id=$row['Programme_Id'];
	  $resultp=mysql_query("SELECT * FROM programme WHERE Programme_Id='$Pro_Id'");
  if($rowp=mysql_fetch_array($resultp))
  {
		$pro_name=$rowp['Programme_Name'];
}
$response=$response.'<option value="'.$pro_name.'">'.$pro_name.'</option>';
  }
$response=$response.'</select>
<div id="stu_year_details">
           <table height="100" class="imgholder">
          <tr>
        <td> </td>
         <td></td>
         </tr>
         <tr>
        <th>        
        </th>
         <td>
        </td>
         </tr> 
          <tr>
        <th>        
         <label>Number of male students:</label>
         </th>
         <td>';
        $response=$response."<input type='text' name='Gra_Male_Students' readonly='readonly'/>";
$response=$response.'</td>
         </tr>
         <tr>
        <th>        
         <label>Number of female students:</label>
         </th>
         <td>';
        $response=$response."<input type='text' name='Gra_Female_Students' readonly='readonly'/>";
$hint=$hint.'</td>
         </tr>
         </table></div></div>';
}
else
{
$response=$hint;
}
echo $response;
?>